package businesslogic.courseselectionbl.Strategy;

import java.util.ArrayList;
import java.util.Iterator;

import po.CourseSelectionPO;

public class RandomDrawStrategy implements DrawStrategy {
	
	
	
	public ArrayList<CourseSelectionPO> draw(ArrayList<CourseSelectionPO> list, int maxStudentNum) {
		if(list.isEmpty()) return new ArrayList<CourseSelectionPO>();
		RandomBase rb = new RandomBase();
		CourseSelectionPO temp;
		for(int i = 0; i <list.size(); i++) {
			int index = rb.getRandomNum(0, list.size()-1);
			temp = list.get(index);
			list.set(index, list.get(i));
			list.set(i, temp);
		}
		ArrayList<CourseSelectionPO> newList = new ArrayList<CourseSelectionPO>();
		Iterator<CourseSelectionPO> itr = list.iterator();
		int i = 0;
		while(itr.hasNext() && i < maxStudentNum) {
			CourseSelectionPO j = itr.next();
			newList.add(j);
			itr.remove();
			i ++;
		}
		return newList;		
	}


	
	
	

}
